package com.gosophia.govDoc.action.turning;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.govDoc.common.TurningAction;
import com.gosophia.govDoc.dto.DocumentJobDataDTO;
import com.gosophia.govDoc.ws.DocumentTurningWebService;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
@Scope("prototype")
@Controller("GetBackAndSubmitApprovalAction")
public class GetBackAndSubmitApprovalAction  extends BaseSupportAction{//用于修改页面【提交审批】按钮，取回并提交

	private Long jobId;
	
	private DocumentJobDataDTO detailData;
	
    private final Logger logger = Logger.getLogger(this.getClass());
    
    private String fromFlag;
    
	@Autowired
	private DocumentTurningWebService documentTurningWebService;
	
	@Override
	public String _execute() throws Exception {
	    //取到当前的操作用户
        UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
        .getContext().getAuthentication().getPrincipal();
        detailData.setOperatorDTO(userDetails.getUserAccountDTO().getUserInfoDTO());
        logger.debug("输出取回并审批后的版本:=>"+ detailData.getDocumentVersion());
		documentTurningWebService.handleDocumentTurning(jobId, detailData, TurningAction.GETBACK_APPROVAL);
		super.getRequestResult().setRsltCode("0");
		super.getRequestResult().setMessage("文档提交审批成功");
		ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
		if("task".equals(fromFlag)){
		    return "TASK";
		}else{
		    return SUCCESS;
		}
	}

	public void setDetailData(DocumentJobDataDTO detailData) {
		this.detailData = detailData;
	}

	public DocumentJobDataDTO getDetailData() {
		return detailData;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public Long getJobId() {
		return jobId;
	}

	public void setFromFlag(String fromFlag) {
		this.fromFlag = fromFlag;
	}

	public String getFromFlag() {
		return fromFlag;
	}

}
